package cn.edu.nwafu.hjpg.dao;

import cn.edu.nwafu.hjpg.entity.Element;
import cn.edu.nwafu.hjpg.entity.Lhsxb;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

import java.util.List;

/**
 * @author Johnny
 * @title: ElementDao
 * @description: TODO
 */
public interface ElementDao extends MongoRepository<Element, String> {
    Element findElementByBaseinfoWzbm(String id);

    Page<Element> findElementsByBaseinfoTypeAndBaseinfoCasLikeOrBaseinfoZwmcLikeOrBaseinfoWzbmLike(String baseinfoType, String baseinfoCas, String baseinfoZwmc, String baseinfoWzbm, Pageable pageable);

    List<Element> findAllByBaseinfoCas(String baseinfoCas);

    void deleteElementByBaseinfoWzbm(String baseinfoWzbm);

    //中文名称 英文名称 cas smiles 搜索功能
    @Query(value = "{$and:[{'baseinfo_type':/?0/},{$or:[{'baseinfo_ywmc':/?1/},{'baseinfo_zwmc':/?3/},{'baseinfo_smiles':/?2/},{'baseinfo_cas':/?4/}]}]}")
    Page<Element> findAllBYBaseinfoTypeAndOther(String type, String baseinfoYwmc, String baseinfoSMILESm, String baseinfoZwmc, String baseinfoCas, Pageable pageable);

    //    Page<Element> findAllByBaseinfoTypeAndBaseinfoYwmcLikeOrBaseinfoCasLikeOrBaseinfoSmilesLikeOrBaseinfoZwmcLike(String type,String baseinfoYwmc,String baseinfoSMILESm,String baseinfoZwmc, String baseinfoCas,Pageable pageable);
//    几种高级搜索
    Page<Element> findAllByBaseinfoZwmcLike(String baseinfoZwmc, Pageable pageable);
    Element findAllByBaseinfoWzbm(String baseinfoWzbm);

    Page<Element> findAllByBaseinfoYwmcLike(String baseinfoYwmc, Pageable pageable);
    Page<Element> findElementsByBaseinfoCasElseLikeOrBaseinfoCasLike(String baseinfoCas,String caseelse, Pageable pageable);
    Page<Element> findAllByBaseinfoSmilesLike(String baseinfoSMILESm, Pageable pageable);


    //    分类功能
    Page<Element> findAllByBaseinfoKindLike(String kind, Pageable pageable);
    Page<Element> findAllByBaseinfoType(String type, Pageable pageable);
    List<Element> findAll();

}
